package com.h.chatroom.controller;

import com.h.chatroom.pojo.dataobject.Message;
import com.h.chatroom.service.MessageService;
import jakarta.annotation.Resource;
import jakarta.validation.constraints.NotNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collections;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/message")
public class MessageController {
    @Resource(name = "messageServiceImpl")
    private MessageService messageService;

    @RequestMapping("/getMessage")
    public List<Message> getMessage(@NotNull(message = "会话Id不能为空") Integer sessionId) {
        log.info("获取的会话中的，对应的会话 Id: " + sessionId);
        List<Message> response = messageService.getMessage(sessionId);
        // 因为最后获取的会话信息都是 降序，也就是最新的信息在顶部，所以需要对其所有信息，进行逆序处理
        Collections.reverse(response);
        return response;
    }
}
